using Core;
using Core.Res;
using System.Collections.Generic;

namespace g_gongjianta
{
    public class PreloadResNode : AbstractSceneNode
    {
        private readonly HashSet<string> resPaths = new();
        private ILoadProgress progress;

        public override void Start()
        {
            CollectSurface();

            CollectMisc();

            Load().Coroutine();
        }

        public override void Finish()
        {
        }

        private async ETVoid Load()
        {
            await G.Res.LoadAsync(resPaths, c => progress = c);
        }

        public override void Update()
        {
            if (progress == null)
            {
                currValue = 1;
                IsComplete = true;
                return;
            }

            currValue = progress.Progress;
            if (progress.State == ELoadState.Complete)
            {
                IsComplete = true;
                currValue = 1;
            }
        }

        private void CollectSurface()
        {
            //var tbl = G.table.Get<TblSurface>();

            //foreach (var item in tbl.Elements)
            //{
            //    resPaths.Add(item.ResPath);
            //}
        }

        private void CollectMisc()
        {
            //resPaths.Add(Global.UnitPrefabPath);

        }
    }
}
